//
//  MobileData.m
//  MobileClass
//
//  Created by cyx on 13-3-12.
//  Copyright (c) 2013年 cyx. All rights reserved.
//

#import "MobileData.h"

static MobileData *mySql = nil;

@implementation MobileData

@synthesize queue;

//获取数据库路径
+(NSString *)getDb
{
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask,YES);
    NSString *documentDirectory = [paths objectAtIndex:0];
    return [documentDirectory stringByAppendingPathComponent:@"MobileClass.db"];
}

+(MobileData*)getMySql
{
    if (!mySql) {
        mySql = [[MobileData alloc] init];
    }
    return mySql;
}

//打开数据库
+(void)openSqlite
{
    [self getMySql];
    mySql.queue = [FMDatabaseQueue databaseQueueWithPath:[self getDb]];

    [mySql.queue inTransaction:^(FMDatabase *db, BOOL *rollback) {
        
        //首页数据表
        [db executeUpdate:@"CREATE TABLE IF NOT EXISTS homedata (userid varchar(50),msg TEXT)"];
        
        //健康动态表
        [db executeUpdate:@"CREATE TABLE IF NOT EXISTS healthdynamic (id varchar(50),msg TEXT)"];
        
        //意见反馈表
        [db executeUpdate:@"CREATE TABLE IF NOT EXISTS feedback (userid varchar(50),id varchar(50),msg TEXT)"];
    }];
}

@end
